package com.yuan.esdemo.controller;

import com.yuan.esdemo.dao.MoviesDao;
import com.yuan.esdemo.entity.Movies;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/movies")
public class MoviesController {
    @Autowired
    private MoviesDao moviesDao;

    @GetMapping("/sb")
    public List<Movies> getPageData(@RequestParam String title,
                                    @RequestParam(defaultValue = "0") int from,
                                    @RequestParam(defaultValue = "10") int size) {
        PageRequest pageRequest = PageRequest.of(from, size);
        return moviesDao.findByTitle(title, pageRequest).getContent();

    }
}
